<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
    <h1>创建axios实例练习</h1>
    <button id="btn">提交按钮</button>

    <script>
        //获取按钮
        const oBtn = document.querySelector('#btn')

        //创建一个axios实例 并对他配置
        const myAxios = axios.create({
            baseURL:'/',
            timeout : 10000,
            headers :{}
        })

        // 给按钮绑定点击事件  发送请求
        btn.onclick =async function(){
           const re =  await myAxios.get('/user',{
                params:{
                    userId:'001'
                }
            })

            //可打印一下请求响应的参数
            console.log(re.data,'re');
        }
    </script>
</body>
</html>